/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package coalescent.is.cef.pui.pob;

import cef.pui.pob.Builder;
import cef.pui.pob.StringBasedBuilder;

import java.math.BigDecimal;
import java.util.Properties;

/**
 * @author Susanta Tewari
 * @version version
 * @history Created on Jul 31, 2012.
 * @since since
 */
@SuppressWarnings("JavaDoc")
public final class Builders_IS {

    /**
     * To avoid instantiation.
     */
    private Builders_IS() {}

    /**
     * Builder for IS sample size of value type {@code Long}. The available properties are:
     * <ul>
     *     <li>{@code coalescent.is.ISSampleSize = valid integer string as specified in } {@link Long#parseLong(java.lang.String)}</li>
     * </ul>
     *
     *
     * @param props properties object containing builder properties
     * @param prefix
     * @return a new builder instance for IS sample size of value type {@code Long}
     */
    public static Builder<Long> getSampleSize(final Properties props, String prefix) {

        if (prefix == null) prefix = "coalescent.is";

        return new StringBasedBuilder<Long>(prefix, props, "ISSampleSize") {

            @Override
            protected Long newInstance(final String propValue) {
                return new Long(propValue);
            }
            @Override
            public String getBuilderString() {
                return "NotYetNecessary";
            }
        };
    }

    /**
     * Builder for exact probability of type {@code BigDecimal}. The available properties are: <ul>
     * <li>{@code coalescent.is.exactProb = valid BigDecimal string as specified in } {@link
     * BigDecimal#BigDecimal(java.lang.String)}</li> </ul>
     *
     *
     *
     * @param props properties object containing builder properties
     * @param prefix
     * @return a new builder instance for IS test sample size of value type {@code BigDecimal}
     */
    public static Builder<BigDecimal> getExactProb(final Properties props, String prefix) {

        return new StringBasedBuilder<BigDecimal>(prefix, props, "exactProb") {

            @Override
            protected BigDecimal newInstance(final String propValue) {

                final BigDecimal result  = new BigDecimal(propValue);
                final double doubleValue = result.doubleValue();

                if ((doubleValue <= 0) || (doubleValue >= 1))
                    throw new IllegalArgumentException("invalid exactProb: " + doubleValue);

                return result;
            }
            @Override
            public String getBuilderString() {
                return "NotYetNecessary";
            }
        };
    }

    /**
     * Properties:
     * <ul>
     *     <li>{@code coalescent.is.isWindowSize = integer }</li>
     * </ul>
     *
     *
     *
     * @param props properties object containing builder properties
     * @param prefix
     * @return a new builder instance for IS window size of type {@code Integer}
     */
    public static Builder<Integer> getWindowSize(final Properties props, String prefix) {

        return new StringBasedBuilder<Integer>(prefix, props, "slidingWindowSize") {

            @Override
            protected Integer newInstance(final String propValue) {
                return new Integer(propValue);
            }
            @Override
            public String getBuilderString() {
                return "NotYetNecessary";
            }
        };
    }

    /**
     * Properties:
     * <ul>
     *     <li>{@code coalescent.is.updateFreq = integer }</li>
     * </ul>
     *
     *
     *
     * @param props builder properties
     * @param prefix
     * @return integer builder for update frequency
     * @see coalescent.is.cef.event.RunSamplers_Evt#getUpdateFreq()
     */
    public static Builder<Integer> getUpdateFreq(final Properties props, String prefix) {

        return new StringBasedBuilder<Integer>(prefix, props, "updateFreq") {

            @Override
            protected Integer newInstance(final String propValue) {
                return new Integer(propValue);
            }
            @Override
            public String getBuilderString() {
                return "NotYetNecessary";
            }
        };
    }

    /**
     * Builder for value type {@code Collection<Sampler<?>>}. The available properties are:
     * <ul>
     *     <li>{@code coalescent.is.ISamplers.gt_EGT = true | false. If true, the properties specified
     *         in } {@link coalescent.cef.pui.pob.Builders_Coa#of_AC_K69_GT_File(java.util.Properties, String)
     *         GeneTree} {@code and } {@link coalescent.cef.pui.pob.Builders_Coa#of_Model_K69(java.util.Properties, String)
     *         K69} {@code need to be present as well.}
     *     </li>
     *     <li>{@code coalescent.is.ISamplers.gt_SD =
     *         true | false. If true, the properties specified in } {@link coalescent.cef.pui.pob.Builders_Coa#of_AC_K69_GT_File(java.util.Properties, String)
     *         GeneTree} {@code and } {@link coalescent.cef.pui.pob.Builders_Coa#of_Model_K69(java.util.Properties, String)
     *         K69} {@code need to be present as well.}
     *     </li>
     *     <li>{@code coalescent.is.ISamplers.gt_SD =
     *         true | false. If true, the properties specified in } {@link coalescent.cef.pui.pob.Builders_Coa#of_AC_K69_GT_File(java.util.Properties, String)
     *         GeneTree} {@code and } {@link coalescent.cef.pui.pob.Builders_Coa#of_Model_K69(java.util.Properties, String)
     *         K69} {@code need to be present as well.}
     *     </li>
     * </ul>
     *
     *
     * @param props properties object containing builder properties
     * @param prefix
     * @param acPrefix
     * @return a new builder instance for {@code Collection<Sampler<?>>}
     */
    public static Samplers_Bldr of_SamplerS(final Properties props, String prefix,
            String acPrefix) {
        return new Samplers_Bldr(props, prefix, acPrefix);
    }

    /**
     * Builder for value type {@code Collection<Sampler<?>>}. The available properties are:
     * <ul>
     *     <li>{@code coalescent.is.MultiISamplers.gt_EGT = true | false. If true, the properties specified
     *          in } {@link coalescent.cef.pui.pob.Builders_Coa#of_AC_K69_GT_File(java.util.Properties, String)
     *          GeneTree} {@code and } {@link coalescent.cef.pui.pob.Builders_Coa#of_Model_K69(java.util.Properties, String)
     *          K69} {@code need to be present as well.}
     *     </li>
     *     <li>{@code coalescent.is.MultiISamplers.gt_SD =
     *         true | false. If true, the properties specified in } {@link coalescent.cef.pui.pob.Builders_Coa#of_AC_K69_GT_File(java.util.Properties, String)
     *         GeneTree} {@code and } {@link coalescent.cef.pui.pob.Builders_Coa#of_Model_K69(java.util.Properties, String)
     *         K69} {@code need to be present as well.}
     *     </li>
     *     <li>{@code coalescent.builder.K69List.theta.min = valid double string as specified in } {@link Double#parseDouble(java.lang.String)}</li>
     *     <li>{@code coalescent.builder.K69List.theta.max = valid double string as specified in } {@link Double#parseDouble(java.lang.String)}</li>
     *     <li>{@code coalescent.builder.K69List.theta.increment = valid double string as specified in } {@link Double#parseDouble(java.lang.String)}</li>
     * </ul>
     *
     *
     * @param props
     * @param prefix
     * @param acPrefix
     * @return
     */
    public static Samplers_Multi_Bldr of_SamplerMultiS(final Properties props, String prefix,
            String acPrefix) {
        return new Samplers_Multi_Bldr(props, prefix, acPrefix);
    }
}
